package 尚硅谷.juc.test12;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum CountryEnum {

    ONE(1,"齐国"),
    TWO(2,"楚国"),
    THREE(3,"燕国"),
    FOUR(4,"赵国"),
    FIVE(5,"魏国"),
    SIX(6,"韩国"),

    ;
    private Integer code;

    private String message;

    /**
     *枚举类给我们提供了values()方法，返回该类型的数据，这样我们就可以通过索引取出该静态变量了
     */
    public static CountryEnum values(int index){
        CountryEnum value = CountryEnum.values()[index];
        return value;
    }

    /**
     * 我们也可以通过values()拿到枚举数组，进行遍历
     */
    public static CountryEnum forEach(int code){
        for (CountryEnum countryEnum:CountryEnum.values()){
            if (countryEnum.getCode()==code){
                 return countryEnum;
            }
        }
        return null;
    }

    public static void main(String[] args) {
        CountryEnum countryEnum = forEach(4);
        System.out.println(countryEnum);
        System.out.println(countryEnum.getCode());
        System.out.println(countryEnum.getMessage());
    }
}
